package com.example.hello.client.Tab;

import com.example.hello.BootstrapTab;
import com.github.gwtbootstrap.client.ui.constants.IconPosition;
import com.github.gwtbootstrap.client.ui.constants.IconSize;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.github.gwtbootstrap.client.ui.resources.Bootstrap;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentContainerConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapTab.class)
public class BootstrapTabConnector extends AbstractComponentContainerConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapTab.class);
    }

    @Override
    public BootstrapTabState getState() {
        return (BootstrapTabState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapTabState state = getState();

        VBootstrapTab tab = new VBootstrapTab();

//        Iterator<Connector> itr = state.getTabPane();
//        while (itr.hasNext()) {
//            tab.add(((ComponentConnector) itr.next()).getWidget());
//        }
        tab.setActive(state.isActive());
        tab.setEnabled(state.isWidgetEnabled());
        tab.setHeading(state.getHeading());
        tab.setIconPosition(IconPosition.valueOf(state.getIconPosition()));
        tab.setIconSize(IconSize.valueOf(state.getIconSize()));
        tab.setIcon(IconType.valueOf(state.getIconType()));
        tab.setStyle(Bootstrap.Tabs.valueOf(state.getStyle()));
    }

    @Override
    public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {

    }

    @Override
    public void updateCaption(ComponentConnector connector) {

    }

}